package myJs.api

import japgolly.scalajs.react.extra.Ajax
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.pojo.App._
import upickle.default._

/**
 * Created by yz on 7/11/2022
 */
object Predict {


  val baseUrl = s"${Api.apiUrl}/predict"

//  def predict(request: PredictData) = {
//    val url = s"${baseUrl}/predict"
//    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
//      read[Predict.Response](str)
//    }
//  }

  def exportPdfs(request: ExportPdfData) = {
    val url = s"${baseUrl}/exportPdfs"
    Ajax("POST", s"${url}").setRequestContentTypeJson
                           .send(write(request))
                           .asAsyncCallback
                           .map { xhr =>
                             read[DirData](xhr.responseText)
                           }
  }

}
